<template>
  <div class="app-container">
    <el-row :gutter="2">
      <el-col :span="16">
        <eHeader :param-bean="paramBean" :sup_this="sup_this" />
        <eForm ref="form" :sup_this="sup_this" />
        <!--表格渲染-->
        <DataGridTable
          v-loading="loading"
          ref="mainTable"
          :sup_this="sup_this"
          :data="data"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          :default-expand-all="expandAll"
          :show-page="false"
          :max-height="gridMaxHeight"
          min-height="400px"
          height="500px"
          row-key="id"
          grid-id="warehouseMngProcessGridId"
          @select-all="gridSelectAllChange"
          @selection-change="handleGridSelectionChange"
          @current-change="handleCurrentChange">
          <el-table-column prop="warehouseName" label="名称" width="300px" >
            <template slot="header" slot-scope="scope">
              <el-link @click="toggleTreeAllExpand">名称 <i class="el-icon-more el-icon--right" /> </el-link>
            </template>
            <template slot-scope="scope">
              <edit :data="scope.row" :sup_this="sup_this" />
            </template>
          </el-table-column>
          <el-table-column prop="thirdCode" label="仓库编码" />
          <el-table-column prop="warehouseLoc" label="仓库位置" />
          <el-table-column prop="warehouseType" label="仓库类别" align="center">
            <template slot-scope="scope">
              <div v-for="item in dicts.warehouse_type" :key="item.id">
                <el-tag v-if="scope.row.warehouseType.toString() === item.dictCode" :type="scope.row.attribute1">{{ item.dictName }}</el-tag>
              </div>
            </template>
          </el-table-column>
        </DataGridTable>
      </el-col>
      <el-col :span="8">
        <storageLocationIndex ref="storageLocationIndex" />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
import eForm from './module/form'
import storageLocationIndex from './storageLocation/storageLocationIndex'
import initData from '@/mixins/initData'
import { loadDataUrl } from '@/api/base/warehouse'

export default {
  components: { storageLocationIndex, eHeader, eForm, edit },
  mixins: [initData],
  // 设置数据字典
  dictTypes: ['warehouse_type'],
  data() {
    return {
      delLoading: false,
      sup_this: this
    }
  },
  created() {
    this.url = loadDataUrl()
    this.searchToggle = true
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    async beforeInit() {
      return true
    },
    handleCurrentChange(row) {
      const _storageLocationIndex = this.$refs.storageLocationIndex
      _storageLocationIndex.warehouseData = row
      _storageLocationIndex.init()
    }
  }
}
</script>
